using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 表单提交记录实体
    /// 用于存储用户提交的表单数据
    /// </summary>
    [Table("form_submissions")]
    public class FormSubmission : ITenantEntity
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        [Key]
        public long Id { get; set; }

        /// <summary>
        /// 表单ID
        /// </summary>
        [Required]
        public long FormId { get; set; }

        /// <summary>
        /// 提交数据
        /// JSON格式存储用户提交的表单数据
        /// </summary>
        [Column(TypeName = "json")]
        public string? Data { get; set; }

        /// <summary>
        /// 提交者IP地址
        /// </summary>
        [StringLength(45)]
        public string? SubmitterIp { get; set; }

        /// <summary>
        /// 提交者用户代理
        /// </summary>
        [StringLength(500)]
        public string? UserAgent { get; set; }

        /// <summary>
        /// 提交者用户ID（如果已登录）
        /// </summary>
        public long? SubmitterId { get; set; }

        /// <summary>
        /// 提交时间
        /// </summary>
        public DateTime SubmitTime { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 处理状态
        /// 0=未处理, 1=已处理, 2=已忽略
        /// </summary>
        public byte Status { get; set; } = 0;

        /// <summary>
        /// 处理人
        /// </summary>
        public long? ProcessedBy { get; set; }

        /// <summary>
        /// 处理时间
        /// </summary>
        public DateTime? ProcessedAt { get; set; }

        /// <summary>
        /// 处理备注
        /// </summary>
        [Column(TypeName = "text")]
        public string? ProcessedNotes { get; set; }

        /// <summary>
        /// 表单导航属性
        /// </summary>
        [ForeignKey(nameof(FormId))]
        public Form? Form { get; set; }

        /// <summary>
        /// 提交者导航属性
        /// </summary>
        [ForeignKey(nameof(SubmitterId))]
        public User? Submitter { get; set; }

        /// <summary>
        /// 处理人导航属性
        /// </summary>
        [ForeignKey(nameof(ProcessedBy))]
        public User? Processor { get; set; }

        /// <summary>
        /// 租户标识符
        /// </summary>
        public string TenantId { get; set; } = string.Empty;
    }
}
